package com.github.rxyor.common.core.util;

import java.lang.reflect.Method;

import lombok.extern.slf4j.Slf4j;

/**
 *<p>
 *
 *</p>
 *
 * @author liuyang
 * @date 2019/8/27 周二 16:45:00
 * @since 1.0.0
 */
@Slf4j
public class ReflectUtil {

    private ReflectUtil() {
    }

    public static Method getNonParameterMethod(Class<?> clazz, String name) {
        if (clazz == null || name == null || name.trim().length() == 0) {
            return null;
        }
        try {
            return clazz.getMethod(name);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }

    @SuppressWarnings("all")
    public static <T> T invokeNonParameterStaticMethod(Method method) {
        if (method == null) {
            return null;
        }
        try {
            return (T)method.invoke(null);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
